
import { layer } from "@layui/layui-vue";
import utils from '../utils/utils';
import webosutils from 'webosutils';
import { h } from "vue";
class FlowUtils {

  resetfield=(v:any,flowjson:any,fieldSource:any)=>{
  
    if (flowjson.value.databases.table == null || flowjson.value.databases.table == "" || flowjson.value.databases.table == undefined) {
      layer.notify({
        title: "温馨提示",
        content: "请先在流程基础信息中配置表"
      });
      return;
    }
   webosutils.http.post("/v1/api/workflow/GetFields", { table: flowjson.value.databases.table }, "请稍等...").then((res:any) => {
      if (res.success) {
        var fields = [];
        //重置表字段
        fieldSource.value=[] ;
        console.log(res);
        for (var i = 0; i < res.data.length; i++) {
          var o = new Object() as any;
          o.check = "0";
          o.status = "0";
          o.field = res.data[i].f_name.toLowerCase();
          fields.push(o);
          o.value=res.data[i].value;
          fieldSource.value.push(o);
        }
        v.fieldStatus= fields;
        layer.notify({
          title: "温馨提示",
          content: res.msg
        });
      } else {
        layer.notify({
          title: "温馨提示",
          content: res.msg
        })
      }

    });
  
}
    // setsetp(d: any,setflowmode:any,fieldSource:any,btValue:any) {
    
    //      }

    //   }
/**
 * 加载流程按钮
 */
      getbutton=(btSource:any)=>{
       webosutils.http.post("/v1/api/workflowtasks/getListButton", { }).then((res:any) => {
          if (res.success) {
              btSource.value=res.data;
          } else {
            layer.msg(res.msg, { icon: 2 });
          }
        }).catch((res:any) => {
          layer.msg("网络错误，请重试", { icon: 2 });
        })
      }

      addfom=(forms:any)=>{
        //加载表单
         
     webosutils.http.post("/v1/api/common/GetCommonList", { tab: "SysFormDesign", page: 1, limit: 1000 }).then((res:any) => {
        if (res.success) {
          forms.value = [];
          res.data.forEach((tab: any) => {
            var o = new Object() as any;
            o.label = tab.title;
            o.value = tab.id;
            forms.value.push(o);
          });
        } else {
          layer.msg(res.msg, { icon: 2 });
        }
      }).catch((res:any) => {
        layer.msg("网络错误，请重试", { icon: 2 });
      })
    }
    adddictionary=(flowtype:any)=>{

     webosutils.http.post("/v1/api/form/GetDictionaryByCode", { id: "FlowTypes" }).then((res:any) => {
        if (res.success) {
          flowtype.value = [];
  
          flowtype.value = utils.TreeTtoList(res.data,[]);

        } else {
          layer.msg(res.msg, { icon: 2 });
        }
      }).catch((res:any) => {
        layer.msg("网络错误，请重试", { icon: 2 });
      })
  
    }
}
export default new FlowUtils()